<!DOCTYPE html>
<html lang="zh-CN">
<head>

    <!--[if lt IE 9]>
        <style>body {display: none; background: none !important} </style>
        <meta http-equiv="Refresh" Content="0; url=//outdatedbrowser.com/" />
    <![endif]-->

<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge, chrome=1" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
<meta name="format-detection" content="telephone=no" />
<meta name="author" content="GosuncnStudio" />



<meta name="description" content="Android statusBar 开发问题汇总适配有虚拟按键的手机，比如华为荣耀系列手机   手机开屏出现白屏和黑屏的解决方法是在开屏的Activity中进行设置自定义的主题：   12345&amp;lt;!-- 防止欢迎页白屏或者黑屏，设置图片或者渐变drawable --&amp;gt;   &amp;lt;style name=&quot;AppTheme.SplashTheme&quot;&amp;gt;       &amp;lt;!--最先">
<meta name="keywords" content="statusBar">
<meta property="og:type" content="article">
<meta property="og:title" content="Android statusBar 开发问题汇总">
<meta property="og:url" content="https://gosuncnstudio.github.io/2017/12/25/Android-statusBar-开发问题汇总/index.html">
<meta property="og:site_name" content="高新兴移动开发小组">
<meta property="og:description" content="Android statusBar 开发问题汇总适配有虚拟按键的手机，比如华为荣耀系列手机   手机开屏出现白屏和黑屏的解决方法是在开屏的Activity中进行设置自定义的主题：   12345&amp;lt;!-- 防止欢迎页白屏或者黑屏，设置图片或者渐变drawable --&amp;gt;   &amp;lt;style name=&quot;AppTheme.SplashTheme&quot;&amp;gt;       &amp;lt;!--最先">
<meta property="og:locale" content="zh-CN">
<meta property="og:image" content="https://gosuncnstudio.github.io/img/AndroidstatusBar开发问题汇总/华为1.jpg">
<meta property="og:image" content="https://gosuncnstudio.github.io/img/AndroidstatusBar开发问题汇总/华为2.jpg">
<meta property="og:image" content="https://gosuncnstudio.github.io/img/AndroidstatusBar开发问题汇总/华为3.jpg">
<meta property="og:image" content="https://gosuncnstudio.github.io/img/AndroidstatusBar开发问题汇总/图片1.png">
<meta property="og:image" content="https://gosuncnstudio.github.io/img/AndroidstatusBar开发问题汇总/图片2.png">
<meta property="og:updated_time" content="2018-01-08T05:54:14.000Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="Android statusBar 开发问题汇总">
<meta name="twitter:description" content="Android statusBar 开发问题汇总适配有虚拟按键的手机，比如华为荣耀系列手机   手机开屏出现白屏和黑屏的解决方法是在开屏的Activity中进行设置自定义的主题：   12345&amp;lt;!-- 防止欢迎页白屏或者黑屏，设置图片或者渐变drawable --&amp;gt;   &amp;lt;style name=&quot;AppTheme.SplashTheme&quot;&amp;gt;       &amp;lt;!--最先">
<meta name="twitter:image" content="https://gosuncnstudio.github.io/img/AndroidstatusBar开发问题汇总/华为1.jpg">

<link rel="apple-touch-icon" href= "/apple-touch-icon.png">




    <link rel="shortcut icon" href="/img/favicon.png">



    <link href="//cdn.bootcss.com/animate.css/3.5.1/animate.min.css" rel="stylesheet">



    <link href="//cdn.bootcss.com/fancybox/2.1.5/jquery.fancybox.min.css" rel="stylesheet">



    <script src="//cdn.bootcss.com/pace/1.0.2/pace.min.js"></script>
    <link href="//cdn.bootcss.com/pace/1.0.2/themes/blue/pace-theme-minimal.css" rel="stylesheet">


<link rel="stylesheet" href="/css/style.css">



<link href="//cdn.bootcss.com/font-awesome/4.6.3/css/font-awesome.min.css" rel="stylesheet">


<title>Android statusBar 开发问题汇总 | 高新兴移动开发小组</title>

<script src="//cdn.bootcss.com/jquery/2.2.4/jquery.min.js"></script>
<script src="//cdn.bootcss.com/clipboard.js/1.5.10/clipboard.min.js"></script>

<script>
    var yiliaConfig = {
        fancybox: true,
        animate: true,
        isHome: false,
        isPost: true,
        isArchive: false,
        isTag: false,
        isCategory: false,
        fancybox_js: "//cdn.bootcss.com/fancybox/2.1.5/jquery.fancybox.min.js",
        scrollreveal: "//cdn.bootcss.com/scrollReveal.js/3.1.4/scrollreveal.min.js",
        search: true
    }
</script>


    <script> yiliaConfig.jquery_ui = [false]; </script>



    <script> yiliaConfig.rootUrl = "\/";</script>






</head>
<body>
  <div id="container">
    <div class="left-col">
    <div class="overlay"></div>
<div class="intrude-less">
    <header id="header" class="inner">
        <a href="/" class="profilepic">
            <img src="/img/avatar.png" class="animated zoomIn">
        </a>
        <hgroup>
          <h1 class="header-author"><a href="/">GosuncnStudio</a></h1>
        </hgroup>

        

        
            <form id="search-form">
            <input type="text" id="local-search-input" name="q" placeholder="search..." class="search form-control" autocomplete="off" autocorrect="off" searchonload="false" />
            <i class="fa fa-times" onclick="resetSearch()"></i>
            </form>
            <div id="local-search-result"></div>
            <p class='no-result'>No results found <i class='fa fa-spinner fa-pulse'></i></p>
        


        
            <div id="switch-btn" class="switch-btn">
                <div class="icon">
                    <div class="icon-ctn">
                        <div class="icon-wrap icon-house" data-idx="0">
                            <div class="birdhouse"></div>
                            <div class="birdhouse_holes"></div>
                        </div>
                        <div class="icon-wrap icon-ribbon hide" data-idx="1">
                            <div class="ribbon"></div>
                        </div>
                        
                        <div class="icon-wrap icon-link hide" data-idx="2">
                            <div class="loopback_l"></div>
                            <div class="loopback_r"></div>
                        </div>
                        
                        
                    </div>
                    
                </div>
                <div class="tips-box hide">
                    <div class="tips-arrow"></div>
                    <ul class="tips-inner">
                        <li>Menu</li>
                        <li>Tags</li>
                        
                        <li>Friends</li>
                        
                        
                    </ul>
                </div>
            </div>
        

        <div id="switch-area" class="switch-area">
            <div class="switch-wrap">
                <section class="switch-part switch-part1">
                    <nav class="header-menu">
                        <ul>
                        
                            <li><a href="/">主页</a></li>
                        
                            <li><a href="/archives/">所有文章</a></li>
                        
                            <li><a href="/tags/">标签云</a></li>
                        
                            <li><a href="/开源项目主页/">开源项目主页</a></li>
                        
                            <li><a href="/优秀推荐/">优秀推荐</a></li>
                        
                        </ul>
                    </nav>
                    <nav class="header-nav">
                        <ul class="social">
                            
                                <a class="fa Email" href="mailto:gosuncn_develop@163.com" title="Email"></a>
                            
                                <a class="fa GitHub" href="https://github.com/GosuncnStudio" title="GitHub"></a>
                            
                        </ul>
                    </nav>
                </section>
                
                
                <section class="switch-part switch-part2">
                    <div class="widget tagcloud" id="js-tagcloud">
                        <ul class="tag-list"><li class="tag-list-item"><a class="tag-list-link" href="/tags/CocoaPods/">CocoaPods</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/Git/">Git</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/SVN/">SVN</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/android/">android</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/hexo/">hexo</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/iOS/">iOS</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/statusBar/">statusBar</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/video/">video</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/内存泄露/">内存泄露</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/注解/">注解</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/生活/">生活</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/线程切换/">线程切换</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/视频码流/">视频码流</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/适配/">适配</a></li></ul>
                    </div>
                </section>
                
                
                
                <section class="switch-part switch-part3">
                    <div id="js-friends">
                    
                      <a class="main-nav-link switch-friends-link" href="https://hexo.io">Hexo</a>
                    
                      <a class="main-nav-link switch-friends-link" href="https://github.com/GosuncnStudio">GitHub</a>
                    
                      <a class="main-nav-link switch-friends-link" href="http://moxfive.xyz/">MOxFIVE</a>
                    
                    </div>
                </section>
                

                
            </div>
        </div>
    </header>                
</div>
    </div>
    <div class="mid-col">
      <nav id="mobile-nav">
      <div class="overlay">
          <div class="slider-trigger"></div>
          <h1 class="header-author js-mobile-header hide"><a href="/" title="回到主页">GosuncnStudio</a></h1>
      </div>
    <div class="intrude-less">
        <header id="header" class="inner">
            <a href="/" class="profilepic">
                <img src="/img/avatar.png" class="animated zoomIn">
            </a>
            <hgroup>
              <h1 class="header-author"><a href="/" title="回到主页">GosuncnStudio</a></h1>
            </hgroup>
            
            <nav class="header-menu">
                <ul>
                
                    <li><a href="/">主页</a></li>
                
                    <li><a href="/archives/">所有文章</a></li>
                
                    <li><a href="/tags/">标签云</a></li>
                
                    <li><a href="/开源项目主页/">开源项目主页</a></li>
                
                    <li><a href="/优秀推荐/">优秀推荐</a></li>
                
                <div class="clearfix"></div>
                </ul>
            </nav>
            <nav class="header-nav">
                        <ul class="social">
                            
                                <a class="fa Email" target="_blank" href="mailto:gosuncn_develop@163.com" title="Email"></a>
                            
                                <a class="fa GitHub" target="_blank" href="https://github.com/GosuncnStudio" title="GitHub"></a>
                            
                        </ul>
            </nav>
        </header>                
    </div>
    <link class="menu-list" tags="Tags" friends="Friends" about="About Me"/>
</nav>
      <div class="body-wrap"><article id="post-Android-statusBar-开发问题汇总" class="article article-type-post" itemscope itemprop="blogPost">
  
    <div class="article-meta">
      <a href="/2017/12/25/Android-statusBar-开发问题汇总/" class="article-date">
      <time datetime="2017-12-25T07:52:45.000Z" itemprop="datePublished">2017-12-25</time>
</a>


    </div>
  
  <div class="article-inner">
    
      <input type="hidden" class="isFancy" />
    
    
      <header class="article-header">
        
  
    <h1 class="article-title" itemprop="name">
      Android statusBar 开发问题汇总
    </h1>
  

      </header>
      
      <div class="article-info article-info-post">
        
    <div class="article-category tagcloud">
    <a class="article-category-link" href="/categories/Android/">Android</a>
    </div>


        
    <div class="article-tag tagcloud">
        <ul class="article-tag-list"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/statusBar/">statusBar</a></li></ul>
    </div>

        <div class="clearfix"></div>
      </div>
      
    
    <div class="article-entry" itemprop="articleBody">
      
          
        <h3 id="Android-statusBar-开发问题汇总"><a href="#Android-statusBar-开发问题汇总" class="headerlink" title="Android statusBar 开发问题汇总"></a>Android statusBar 开发问题汇总</h3><h4 id="适配有虚拟按键的手机，比如华为荣耀系列手机"><a href="#适配有虚拟按键的手机，比如华为荣耀系列手机" class="headerlink" title="适配有虚拟按键的手机，比如华为荣耀系列手机"></a>适配有虚拟按键的手机，比如华为荣耀系列手机</h4><p>   手机开屏出现白屏和黑屏的解决方法是在开屏的Activity中进行设置自定义的主题：<br>   <figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">&lt;!-- 防止欢迎页白屏或者黑屏，设置图片或者渐变drawable --&gt;</span></span><br><span class="line">   <span class="tag">&lt;<span class="name">style</span> <span class="attr">name</span>=<span class="string">"AppTheme.SplashTheme"</span>&gt;</span><span class="undefined"></span></span><br><span class="line"><span class="xml">       <span class="comment">&lt;!--最先呈现给用户查看--&gt;</span></span></span><br><span class="line"><span class="xml">       <span class="tag">&lt;<span class="name">item</span> <span class="attr">name</span>=<span class="string">"android:windowBackground"</span>&gt;</span>@drawable/shape_bg_start_page<span class="tag">&lt;/<span class="name">item</span>&gt;</span></span></span><br><span class="line"><span class="undefined">       </span><span class="tag">&lt;/<span class="name">style</span>&gt;</span></span><br></pre></td></tr></table></figure></p>
<p>   在其他手机上如上诉代码设置即可，但在华为手机上会发现虚拟按钮及顶部statusBar跟自己设置的主题颜色很不协调。其颜色<br>   默认为 <strong> 黑底白字 </strong>。<br>   可以添加如下代码进行设置：</p>
   <figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">&lt;!-- 防止欢迎页白屏或者黑屏，设置图片 --&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">style</span> <span class="attr">name</span>=<span class="string">"AppTheme.SplashTheme"</span>&gt;</span><span class="undefined"></span></span><br><span class="line"><span class="xml">        <span class="comment">&lt;!--最先呈现给用户查看--&gt;</span></span></span><br><span class="line"><span class="xml">        <span class="tag">&lt;<span class="name">item</span> <span class="attr">name</span>=<span class="string">"android:windowBackground"</span>&gt;</span>@drawable/shape_bg_start_page<span class="tag">&lt;/<span class="name">item</span>&gt;</span></span></span><br><span class="line"><span class="xml">        <span class="comment">&lt;!--考虑华为手机虚拟按键的显示--&gt;</span></span></span><br><span class="line"><span class="xml">        <span class="tag">&lt;<span class="name">item</span> <span class="attr">name</span>=<span class="string">"android:windowTranslucentNavigation"</span>&gt;</span>true<span class="tag">&lt;/<span class="name">item</span>&gt;</span></span></span><br><span class="line"><span class="xml">        <span class="tag">&lt;<span class="name">item</span> <span class="attr">name</span>=<span class="string">"android:windowTranslucentStatus"</span>&gt;</span>true<span class="tag">&lt;/<span class="name">item</span>&gt;</span></span></span><br><span class="line"><span class="undefined">    </span><span class="tag">&lt;/<span class="name">style</span>&gt;</span></span><br></pre></td></tr></table></figure>
<a id="more"></a>
<p>最后得到如图<br><img src="/img/AndroidstatusBar开发问题汇总/华为1.jpg" alt="华为1.jpg">    <img src="/img/AndroidstatusBar开发问题汇总/华为2.jpg" alt="华为2.jpg"></p>
<p><img src="/img/AndroidstatusBar开发问题汇总/华为3.jpg" alt="华为3.jpg"></p>
<ul>
<li>可从图片上观察到虚拟按键和statuBar的背景色和自定义的主题色进行了很好的== 拉伸过渡==<h4 id="设置statusBar颜色-适配4-4以上系统"><a href="#设置statusBar颜色-适配4-4以上系统" class="headerlink" title="设置statusBar颜色 适配4.4以上系统"></a>设置statusBar颜色 适配4.4以上系统</h4>但实现上述的效果图，可不仅仅依靠上面两行代码，上面两行代码只是针对开屏页进行了设置。<strong> 后续界面的实现请看下面代码： </strong><br>为了考虑不同手机的兼容性及不同api（api&gt;=19 即adnroid 4.4版本）,不同手机版本的statusBar的高度各有不同，所以按如下步骤进行处理：</li>
</ul>
<ul>
<li><p><strong> 第一步：获取statusbar的高度</strong><br>参考如下代码：</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> * 获取状态栏高度</span></span><br><span class="line"><span class="comment"> *</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@param</span> context context</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@return</span> 状态栏高度</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"><span class="function"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">int</span> <span class="title">getStatusBarHeight</span><span class="params">(Context context)</span> </span>&#123;</span><br><span class="line">    <span class="keyword">int</span> result = -<span class="number">1</span>;</span><br><span class="line">    <span class="keyword">int</span> resourceId = context.getResources().getIdentifier(<span class="string">"status_bar_height"</span>, <span class="string">"dimen"</span>, <span class="string">"android"</span>);</span><br><span class="line">    <span class="keyword">if</span> (resourceId &gt; <span class="number">0</span>) &#123;</span><br><span class="line">        result = context.getResources().getDimensionPixelSize(resourceId);</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="keyword">return</span> result;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>以上工具类方法可从 <a href="https://github.com/GosuncnMobile/BaseLibrary/blob/master/util/src/main/java/com/gosuncn/core/util/view/StatusBarUtils.java" target="_blank" rel="noopener">CommonUtil库</a>进行获取。</p>
</li>
<li><p><strong> 第二步：创建一个和statusBar高度一致的颜色块</strong></p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br></pre></td><td class="code"><pre><span class="line">    <span class="comment">/**</span></span><br><span class="line"><span class="comment">     * 生成一个和状态栏大小相同的矩形条</span></span><br><span class="line"><span class="comment">     *</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@param</span> activity 需要设置的activity</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@param</span> color    状态栏颜色值</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@return</span> 状态栏矩形条</span></span><br><span class="line"><span class="comment">     */</span></span><br><span class="line">    <span class="function"><span class="keyword">private</span> <span class="keyword">static</span> View <span class="title">createStatusBarView</span><span class="params">(Activity activity, <span class="keyword">int</span> color)</span> </span>&#123;</span><br><span class="line">        <span class="comment">// 获得状态栏高度</span></span><br><span class="line"><span class="comment">//        int resourceId = activity.getResources().getIdentifier("status_bar_height", "dimen", "android");</span></span><br><span class="line"><span class="comment">//        int statusBarHeight = activity.getResources().getDimensionPixelSize(resourceId);</span></span><br><span class="line">        <span class="keyword">int</span> statusBarHeight = StatusBarUtils.getStatusBarHeight(activity);</span><br><span class="line">        Log.e(TAG, <span class="string">"createStatusView: statusBarHeight = "</span> + statusBarHeight);</span><br><span class="line">        <span class="comment">// 绘制一个和状态栏一样高的矩形</span></span><br><span class="line">        View statusView = <span class="keyword">new</span> View(activity);</span><br><span class="line">        LinearLayout.LayoutParams params = <span class="keyword">new</span> LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,</span><br><span class="line">                statusBarHeight);</span><br><span class="line">        statusView.setLayoutParams(params);</span><br><span class="line">        statusView.setBackgroundColor(color);</span><br><span class="line">        <span class="keyword">return</span> statusView;</span><br><span class="line">    &#125;</span><br></pre></td></tr></table></figure>
</li>
<li><p><strong> 第三步：设置statusBar透明，添加自定义statusBar 颜色 </strong></p>
</li>
</ul>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//使状态栏透明</span></span><br><span class="line"><span class="meta">@TargetApi</span>(Build.VERSION_CODES.KITKAT)</span><br><span class="line"><span class="function"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title">transparentStatusBar</span><span class="params">(Activity activity, <span class="keyword">int</span> color)</span> </span>&#123;</span><br><span class="line">    <span class="keyword">if</span> (Build.VERSION.SDK_INT &gt;= Build.VERSION_CODES.KITKAT) &#123;<span class="comment">//4.4 全透明状态栏</span></span><br><span class="line">        <span class="comment">//  这个属性4.4算是全透明（有的机子是过渡形式的透明），5.0则是半透明，某些手机则是全透明。</span></span><br><span class="line">        activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);</span><br><span class="line">        activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);</span><br><span class="line"></span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="keyword">if</span> (Build.VERSION.SDK_INT &gt;= Build.VERSION_CODES.LOLLIPOP) &#123;<span class="comment">//5.0 全透明实现</span></span><br><span class="line">        Window window = activity.getWindow();</span><br><span class="line">        <span class="comment">//// 因为EMUI3.1系统与这种沉浸式方案API有点冲突，会没有沉浸式效果。</span></span><br><span class="line">        <span class="comment">// 所以这里加了判断，EMUI3.1系统不清除FLAG_TRANSLUCENT_STATUS</span></span><br><span class="line">        <span class="keyword">if</span> (!isEMUI3_1()) &#123;</span><br><span class="line">            window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);</span><br><span class="line">        &#125;</span><br><span class="line">        window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);</span><br><span class="line">        window.setStatusBarColor(Color.TRANSPARENT);</span><br><span class="line">        window.setNavigationBarColor(Color.TRANSPARENT);</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    Log.e(TAG, <span class="string">"transparentStatusBar: color = "</span> + color);</span><br><span class="line">    <span class="keyword">if</span> (Build.VERSION.SDK_INT &gt;= Build.VERSION_CODES.M) &#123;</span><br><span class="line">        <span class="keyword">boolean</span> isLightTheme = <span class="keyword">false</span>;</span><br><span class="line">        Window window = activity.getWindow();</span><br><span class="line">        <span class="keyword">for</span> (<span class="keyword">int</span> i = <span class="number">0</span>; i &lt; lightColors.length; i++) &#123;</span><br><span class="line">            <span class="keyword">int</span> selectColor = activity.getColor(lightColors[i]);</span><br><span class="line">            <span class="keyword">if</span> (selectColor == color) &#123;</span><br><span class="line">                isLightTheme = <span class="keyword">true</span>;</span><br><span class="line">                <span class="keyword">break</span>;</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="comment">//如果是白色系列主题，则设置为黑字，默认是白字</span></span><br><span class="line">        <span class="keyword">if</span> (isLightTheme) &#123;</span><br><span class="line">            window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);</span><br><span class="line">        &#125;</span><br><span class="line"></span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">boolean</span> <span class="title">isEMUI3_1</span><span class="params">()</span> </span>&#123;</span><br><span class="line">    <span class="keyword">if</span> (<span class="string">"EmotionUI_3.1"</span>.equals(getEmuiVersion())) &#123;</span><br><span class="line">        <span class="keyword">return</span> <span class="keyword">true</span>;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="keyword">return</span> <span class="keyword">false</span>;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">private</span> <span class="keyword">static</span> String <span class="title">getEmuiVersion</span><span class="params">()</span> </span>&#123;</span><br><span class="line">    Class&lt;?&gt; classType = <span class="keyword">null</span>;</span><br><span class="line">    <span class="keyword">try</span> &#123;</span><br><span class="line">        classType = Class.forName(<span class="string">"android.os.SystemProperties"</span>);</span><br><span class="line">        Method getMethod = classType.getDeclaredMethod(<span class="string">"get"</span>, String.class);</span><br><span class="line">        <span class="keyword">return</span> (String) getMethod.invoke(classType, <span class="string">"ro.build.version.emui"</span>);</span><br><span class="line">    &#125; <span class="keyword">catch</span> (ClassNotFoundException e) &#123;</span><br><span class="line">        e.printStackTrace();</span><br><span class="line">    &#125; <span class="keyword">catch</span> (NoSuchMethodException e) &#123;</span><br><span class="line">        e.printStackTrace();</span><br><span class="line">    &#125; <span class="keyword">catch</span> (IllegalAccessException e) &#123;</span><br><span class="line">        e.printStackTrace();</span><br><span class="line">    &#125; <span class="keyword">catch</span> (InvocationTargetException e) &#123;</span><br><span class="line">        e.printStackTrace();</span><br><span class="line">    &#125; <span class="keyword">catch</span> (Exception e) &#123;</span><br><span class="line">        e.printStackTrace();</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="keyword">return</span> <span class="string">""</span>;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h5 id="对上述代码修改补充-2017-12-27-：华为EMUI3-1系统-statusBar-的特殊处理"><a href="#对上述代码修改补充-2017-12-27-：华为EMUI3-1系统-statusBar-的特殊处理" class="headerlink" title="对上述代码修改补充(2017/12/27)：华为EMUI3.1系统 statusBar 的特殊处理"></a>对上述代码修改补充(2017/12/27)：华为EMUI3.1系统 statusBar 的特殊处理</h5><ul>
<li><strong> 第四步：设置statusBar颜色 </strong></li>
</ul>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//设置状态栏颜色</span></span><br><span class="line">     <span class="function"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title">setColor</span><span class="params">(Activity activity, <span class="keyword">int</span> color)</span> </span>&#123;</span><br><span class="line">      <span class="keyword">if</span> (Build.VERSION.SDK_INT &gt;= Build.VERSION_CODES.KITKAT) &#123;</span><br><span class="line">          <span class="comment">// 设置状态栏透明</span></span><br><span class="line">          <span class="comment">//  activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);</span></span><br><span class="line">          transparentStatusBar(activity);</span><br><span class="line">          <span class="comment">// 生成一个状态栏大小的矩形</span></span><br><span class="line">          View statusView = createStatusBarView(activity, color);</span><br><span class="line">          <span class="comment">// 添加 statusView 到布局中</span></span><br><span class="line">          ViewGroup decorView = (ViewGroup) activity.getWindow().getDecorView();</span><br><span class="line">          decorView.addView(statusView);</span><br><span class="line">          <span class="comment">//   设置根布局的参数</span></span><br><span class="line">          ViewGroup contentLayout = (ViewGroup) ((ViewGroup) 			activity.findViewById(android.R.id.content)).getChildAt(<span class="number">0</span>);</span><br><span class="line">          Log.w(TAG, <span class="string">"setColor: content paddingTop before set = "</span> + contentLayout.getPaddingTop());</span><br><span class="line">          contentLayout.setFitsSystemWindows(<span class="keyword">true</span>);</span><br><span class="line">          contentLayout.setClipToPadding(<span class="keyword">true</span>);</span><br><span class="line">          Log.w(TAG, <span class="string">"setColor: content paddingTop after set = "</span> + contentLayout.getPaddingTop());</span><br><span class="line">          <span class="comment">//为了适配不同手机的情况，可以在基类activity 中监听onWindowsFocusChange()看看根布局的padding是否等于</span></span><br><span class="line">          <span class="comment">//statusBar的高度，如果不等于（几乎大部分手机都是相等的，目前遇到的情况是努比亚的手机设置的padingTop特别小，</span></span><br><span class="line">          <span class="comment">// 导致内容布局与statusBar重叠） ，则手动设置paddingTop为statusBar的高度。</span></span><br><span class="line"></span><br><span class="line"></span><br><span class="line">      &#125;</span><br><span class="line">  &#125;</span><br></pre></td></tr></table></figure>
<ul>
<li><strong> 第五步：在基类中设置statusBar (在setContentView(…)之后设置)</strong></li>
</ul>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@Override</span></span><br><span class="line">   <span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">afterSetContentView</span><span class="params">()</span> </span>&#123;</span><br><span class="line">       StatusBarUtil.setColor(<span class="keyword">this</span>, getResources().getColor(R.color.app_white_bg));</span><br><span class="line">       initViews();</span><br><span class="line">       initData();</span><br><span class="line">   &#125;</span><br></pre></td></tr></table></figure>
<h4 id="填坑指南"><a href="#填坑指南" class="headerlink" title="填坑指南"></a>填坑指南</h4><p>  <code>关键的一步，主要是努比亚的手机的系统定制的比较特殊，在fitSystemWindow之后，对于根布局contentLayout设置的paddingTop并不等于 statusBar的高度，所以导致了内容布局会与statusBar重叠！！！网上的做法都是说重叠了就设置fitSystemWindow就可以，目前尚无对应的处理方法，所以接下来的解决方法就可能是你苦苦寻求的啦</code><br>  <figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> * 监听是否有设置正常的padding，有一些手机如努比亚手机就不会设置正常的statusBar的高度作为padding，</span></span><br><span class="line"><span class="comment"> * 导致内容布局与statusBar重叠的问题。</span></span><br><span class="line"><span class="comment"> *</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@param</span> hasFocus</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"><span class="meta">@Override</span></span><br><span class="line"><span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">onWindowFocusChanged</span><span class="params">(<span class="keyword">boolean</span> hasFocus)</span> </span>&#123;</span><br><span class="line">    <span class="keyword">super</span>.onWindowFocusChanged(hasFocus);</span><br><span class="line">    Log.e(TAG, <span class="string">"onWindowFocusChanged: binding.getRoot().getPaddingTop() = "</span> + binding.getRoot().getPaddingTop());</span><br><span class="line">    <span class="keyword">if</span> (binding.getRoot().getPaddingTop() != StatusBarUtils.getStatusBarHeight(<span class="keyword">this</span>)) &#123;</span><br><span class="line">        binding.getRoot().setPadding(<span class="number">0</span>, StatusBarUtils.getStatusBarHeight(<span class="keyword">this</span>), <span class="number">0</span>, <span class="number">0</span>);</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></p>
<h6 id="其实解决思路是很简单的，主要是找出问题的根源所在。还有一点就是在写界面布局时，-注意不要轻易在根布局里面设置paddingTop属性，经过测试发现，这个-paddingTop会被系统在fitSystemWindow之后帮你设置为-statusBar的高度（除了上面那个特殊情况，需要自己设置paddingTop）"><a href="#其实解决思路是很简单的，主要是找出问题的根源所在。还有一点就是在写界面布局时，-注意不要轻易在根布局里面设置paddingTop属性，经过测试发现，这个-paddingTop会被系统在fitSystemWindow之后帮你设置为-statusBar的高度（除了上面那个特殊情况，需要自己设置paddingTop）" class="headerlink" title="其实解决思路是很简单的，主要是找出问题的根源所在。还有一点就是在写界面布局时， 注意不要轻易在根布局里面设置paddingTop属性，经过测试发现，这个 paddingTop会被系统在fitSystemWindow之后帮你设置为 statusBar的高度（除了上面那个特殊情况，需要自己设置paddingTop）"></a>其实解决思路是很简单的，主要是找出问题的根源所在。还有一点就是在写界面布局时，<strong> 注意不要轻易在根布局里面设置paddingTop属性</strong>，经过测试发现，这个<strong> paddingTop</strong>会被系统在fitSystemWindow之后帮你设置为<strong> statusBar的高度</strong>（除了上面那个特殊情况，需要自己设置paddingTop）</h6><h4 id="附带：一个分析布局的工具Layout-Inspector"><a href="#附带：一个分析布局的工具Layout-Inspector" class="headerlink" title="附带：一个分析布局的工具Layout Inspector"></a>附带：一个分析布局的工具Layout Inspector</h4><p><img src="/img/AndroidstatusBar开发问题汇总/图片1.png" alt="图片1.png"></p>
<p><img src="/img/AndroidstatusBar开发问题汇总/图片2.png" alt="图片2.png"></p>
<p><strong> 附录·参考文献 </strong><br><a href="http://blog.chengyunfeng.com/?p=905#ixzz52GUtJQnQ" target="_blank" rel="noopener">该使用 fitsSystemWindows 了</a><br><a href="http://www.liuling123.com/2017/02/transparent-status-bar.html" target="_blank" rel="noopener">沉浸式状态栏实现及遇到的坑</a><strong> (重点推荐！) </strong></p>

      
    </div>
    
  </div>
  
    
    <div class="copyright">
        <p><span>Title:</span><a href="/2017/12/25/Android-statusBar-开发问题汇总/">Android statusBar 开发问题汇总</a></p>
        <p><span>Author:</span><a href="/" title="Back to Homepage">GosuncnStudio</a></p>
        <p><span>Created:</span>2017-12-25, 15:52:45</p>
        <p><span>Updated:</span>2018-01-08, 13:54:14</p>
        <p>
            <span>Full URL:</span><a class="post-url" href="/2017/12/25/Android-statusBar-开发问题汇总/" title="Android statusBar 开发问题汇总">https://gosuncnstudio.github.io/2017/12/25/Android-statusBar-开发问题汇总/</a>
            <span class="copy-path" data-clipboard-text="From https://gosuncnstudio.github.io/2017/12/25/Android-statusBar-开发问题汇总/　　By GosuncnStudio" title="Copy Article&#39;s Link &amp; Author"><i class="fa fa-clipboard"></i></span>
            <script> var clipboard = new Clipboard('.copy-path'); </script>
        </p>
        <p>
            <span>License:</span><i class="fa fa-creative-commons"></i> <a rel="license" href="http://creativecommons.org/licenses/by-nc-sa/4.0/" title="CC BY-NC-SA 4.0 International" target = "_blank">"CC BY-NC-SA 4.0"</a> Keep Link &amp; Author if Distribute.
        </p>
    </div>



    <nav id="article-nav">
        
            <div id="article-nav-newer" class="article-nav-title">
                <a href="/2017/12/27/Android编译时注解/">
                    Android编译时注解
                </a>
            </div>
        
        
            <div id="article-nav-older" class="article-nav-title">
                <a href="/2017/12/18/Git常用命令简介/">
                    Git常用命令简介
                </a>
            </div>
        
    </nav>

  
</article>

    <div id="toc" class="toc-article">
        <strong class="toc-title">Contents</strong>
        
            <ol class="toc"><li class="toc-item toc-level-3"><a class="toc-link" href="#Android-statusBar-开发问题汇总"><span class="toc-number">1.</span> <span class="toc-text"><a href="#Android-statusBar-&#x5F00;&#x53D1;&#x95EE;&#x9898;&#x6C47;&#x603B;" class="headerlink" title="Android statusBar &#x5F00;&#x53D1;&#x95EE;&#x9898;&#x6C47;&#x603B;"></a>Android statusBar &#x5F00;&#x53D1;&#x95EE;&#x9898;&#x6C47;&#x603B;</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#适配有虚拟按键的手机，比如华为荣耀系列手机"><span class="toc-number">1.1.</span> <span class="toc-text"><a href="#&#x9002;&#x914D;&#x6709;&#x865A;&#x62DF;&#x6309;&#x952E;&#x7684;&#x624B;&#x673A;&#xFF0C;&#x6BD4;&#x5982;&#x534E;&#x4E3A;&#x8363;&#x8000;&#x7CFB;&#x5217;&#x624B;&#x673A;" class="headerlink" title="&#x9002;&#x914D;&#x6709;&#x865A;&#x62DF;&#x6309;&#x952E;&#x7684;&#x624B;&#x673A;&#xFF0C;&#x6BD4;&#x5982;&#x534E;&#x4E3A;&#x8363;&#x8000;&#x7CFB;&#x5217;&#x624B;&#x673A;"></a>&#x9002;&#x914D;&#x6709;&#x865A;&#x62DF;&#x6309;&#x952E;&#x7684;&#x624B;&#x673A;&#xFF0C;&#x6BD4;&#x5982;&#x534E;&#x4E3A;&#x8363;&#x8000;&#x7CFB;&#x5217;&#x624B;&#x673A;</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#设置statusBar颜色-适配4-4以上系统"><span class="toc-number">1.2.</span> <span class="toc-text"><a href="#&#x8BBE;&#x7F6E;statusBar&#x989C;&#x8272;-&#x9002;&#x914D;4-4&#x4EE5;&#x4E0A;&#x7CFB;&#x7EDF;" class="headerlink" title="&#x8BBE;&#x7F6E;statusBar&#x989C;&#x8272; &#x9002;&#x914D;4.4&#x4EE5;&#x4E0A;&#x7CFB;&#x7EDF;"></a>&#x8BBE;&#x7F6E;statusBar&#x989C;&#x8272; &#x9002;&#x914D;4.4&#x4EE5;&#x4E0A;&#x7CFB;&#x7EDF;</span></a><ol class="toc-child"><li class="toc-item toc-level-5"><a class="toc-link" href="#对上述代码修改补充-2017-12-27-：华为EMUI3-1系统-statusBar-的特殊处理"><span class="toc-number">1.2.1.</span> <span class="toc-text"><a href="#&#x5BF9;&#x4E0A;&#x8FF0;&#x4EE3;&#x7801;&#x4FEE;&#x6539;&#x8865;&#x5145;-2017-12-27-&#xFF1A;&#x534E;&#x4E3A;EMUI3-1&#x7CFB;&#x7EDF;-statusBar-&#x7684;&#x7279;&#x6B8A;&#x5904;&#x7406;" class="headerlink" title="&#x5BF9;&#x4E0A;&#x8FF0;&#x4EE3;&#x7801;&#x4FEE;&#x6539;&#x8865;&#x5145;(2017/12/27)&#xFF1A;&#x534E;&#x4E3A;EMUI3.1&#x7CFB;&#x7EDF; statusBar &#x7684;&#x7279;&#x6B8A;&#x5904;&#x7406;"></a>&#x5BF9;&#x4E0A;&#x8FF0;&#x4EE3;&#x7801;&#x4FEE;&#x6539;&#x8865;&#x5145;(2017/12/27)&#xFF1A;&#x534E;&#x4E3A;EMUI3.1&#x7CFB;&#x7EDF; statusBar &#x7684;&#x7279;&#x6B8A;&#x5904;&#x7406;</span></a></li></ol></li><li class="toc-item toc-level-4"><a class="toc-link" href="#填坑指南"><span class="toc-number">1.3.</span> <span class="toc-text"><a href="#&#x586B;&#x5751;&#x6307;&#x5357;" class="headerlink" title="&#x586B;&#x5751;&#x6307;&#x5357;"></a>&#x586B;&#x5751;&#x6307;&#x5357;</span></a><ol class="toc-child"><li class="toc-item toc-level-6"><a class="toc-link" href="#其实解决思路是很简单的，主要是找出问题的根源所在。还有一点就是在写界面布局时，-注意不要轻易在根布局里面设置paddingTop属性，经过测试发现，这个-paddingTop会被系统在fitSystemWindow之后帮你设置为-statusBar的高度（除了上面那个特殊情况，需要自己设置paddingTop）"><span class="toc-number">1.3.0.1.</span> <span class="toc-text"><a href="#&#x5176;&#x5B9E;&#x89E3;&#x51B3;&#x601D;&#x8DEF;&#x662F;&#x5F88;&#x7B80;&#x5355;&#x7684;&#xFF0C;&#x4E3B;&#x8981;&#x662F;&#x627E;&#x51FA;&#x95EE;&#x9898;&#x7684;&#x6839;&#x6E90;&#x6240;&#x5728;&#x3002;&#x8FD8;&#x6709;&#x4E00;&#x70B9;&#x5C31;&#x662F;&#x5728;&#x5199;&#x754C;&#x9762;&#x5E03;&#x5C40;&#x65F6;&#xFF0C;-&#x6CE8;&#x610F;&#x4E0D;&#x8981;&#x8F7B;&#x6613;&#x5728;&#x6839;&#x5E03;&#x5C40;&#x91CC;&#x9762;&#x8BBE;&#x7F6E;paddingTop&#x5C5E;&#x6027;&#xFF0C;&#x7ECF;&#x8FC7;&#x6D4B;&#x8BD5;&#x53D1;&#x73B0;&#xFF0C;&#x8FD9;&#x4E2A;-paddingTop&#x4F1A;&#x88AB;&#x7CFB;&#x7EDF;&#x5728;fitSystemWindow&#x4E4B;&#x540E;&#x5E2E;&#x4F60;&#x8BBE;&#x7F6E;&#x4E3A;-statusBar&#x7684;&#x9AD8;&#x5EA6;&#xFF08;&#x9664;&#x4E86;&#x4E0A;&#x9762;&#x90A3;&#x4E2A;&#x7279;&#x6B8A;&#x60C5;&#x51B5;&#xFF0C;&#x9700;&#x8981;&#x81EA;&#x5DF1;&#x8BBE;&#x7F6E;paddingTop&#xFF09;" class="headerlink" title="&#x5176;&#x5B9E;&#x89E3;&#x51B3;&#x601D;&#x8DEF;&#x662F;&#x5F88;&#x7B80;&#x5355;&#x7684;&#xFF0C;&#x4E3B;&#x8981;&#x662F;&#x627E;&#x51FA;&#x95EE;&#x9898;&#x7684;&#x6839;&#x6E90;&#x6240;&#x5728;&#x3002;&#x8FD8;&#x6709;&#x4E00;&#x70B9;&#x5C31;&#x662F;&#x5728;&#x5199;&#x754C;&#x9762;&#x5E03;&#x5C40;&#x65F6;&#xFF0C; &#x6CE8;&#x610F;&#x4E0D;&#x8981;&#x8F7B;&#x6613;&#x5728;&#x6839;&#x5E03;&#x5C40;&#x91CC;&#x9762;&#x8BBE;&#x7F6E;paddingTop&#x5C5E;&#x6027;&#xFF0C;&#x7ECF;&#x8FC7;&#x6D4B;&#x8BD5;&#x53D1;&#x73B0;&#xFF0C;&#x8FD9;&#x4E2A; paddingTop&#x4F1A;&#x88AB;&#x7CFB;&#x7EDF;&#x5728;fitSystemWindow&#x4E4B;&#x540E;&#x5E2E;&#x4F60;&#x8BBE;&#x7F6E;&#x4E3A; statusBar&#x7684;&#x9AD8;&#x5EA6;&#xFF08;&#x9664;&#x4E86;&#x4E0A;&#x9762;&#x90A3;&#x4E2A;&#x7279;&#x6B8A;&#x60C5;&#x51B5;&#xFF0C;&#x9700;&#x8981;&#x81EA;&#x5DF1;&#x8BBE;&#x7F6E;paddingTop&#xFF09;"></a>&#x5176;&#x5B9E;&#x89E3;&#x51B3;&#x601D;&#x8DEF;&#x662F;&#x5F88;&#x7B80;&#x5355;&#x7684;&#xFF0C;&#x4E3B;&#x8981;&#x662F;&#x627E;&#x51FA;&#x95EE;&#x9898;&#x7684;&#x6839;&#x6E90;&#x6240;&#x5728;&#x3002;&#x8FD8;&#x6709;&#x4E00;&#x70B9;&#x5C31;&#x662F;&#x5728;&#x5199;&#x754C;&#x9762;&#x5E03;&#x5C40;&#x65F6;&#xFF0C;<strong> &#x6CE8;&#x610F;&#x4E0D;&#x8981;&#x8F7B;&#x6613;&#x5728;&#x6839;&#x5E03;&#x5C40;&#x91CC;&#x9762;&#x8BBE;&#x7F6E;paddingTop&#x5C5E;&#x6027;</strong>&#xFF0C;&#x7ECF;&#x8FC7;&#x6D4B;&#x8BD5;&#x53D1;&#x73B0;&#xFF0C;&#x8FD9;&#x4E2A;<strong> paddingTop</strong>&#x4F1A;&#x88AB;&#x7CFB;&#x7EDF;&#x5728;fitSystemWindow&#x4E4B;&#x540E;&#x5E2E;&#x4F60;&#x8BBE;&#x7F6E;&#x4E3A;<strong> statusBar&#x7684;&#x9AD8;&#x5EA6;</strong>&#xFF08;&#x9664;&#x4E86;&#x4E0A;&#x9762;&#x90A3;&#x4E2A;&#x7279;&#x6B8A;&#x60C5;&#x51B5;&#xFF0C;&#x9700;&#x8981;&#x81EA;&#x5DF1;&#x8BBE;&#x7F6E;paddingTop&#xFF09;</span></a></li></ol></li></ol></li><li class="toc-item toc-level-4"><a class="toc-link" href="#附带：一个分析布局的工具Layout-Inspector"><span class="toc-number">1.4.</span> <span class="toc-text"><a href="#&#x9644;&#x5E26;&#xFF1A;&#x4E00;&#x4E2A;&#x5206;&#x6790;&#x5E03;&#x5C40;&#x7684;&#x5DE5;&#x5177;Layout-Inspector" class="headerlink" title="&#x9644;&#x5E26;&#xFF1A;&#x4E00;&#x4E2A;&#x5206;&#x6790;&#x5E03;&#x5C40;&#x7684;&#x5DE5;&#x5177;Layout Inspector"></a>&#x9644;&#x5E26;&#xFF1A;&#x4E00;&#x4E2A;&#x5206;&#x6790;&#x5E03;&#x5C40;&#x7684;&#x5DE5;&#x5177;Layout Inspector</span></a></li></ol></li></ol>
        
    </div>
    <style>
        .left-col .switch-btn,
        .left-col .switch-area {
            display: none;
        }
        .toc-level-3 i,
        .toc-level-3 ol {
            display: none !important;
        }
    </style>

    <input type="button" id="tocButton" value="Hide"  title="Show or Hide Table of Contents">

    <script>
        yiliaConfig.toc = ["Hide", "Show", !!"false"];
    </script>



    
<div class="share">
    
        <div class="bdsharebuttonbox">
            <a href="#" class="fa fa-twitter bds_twi" data-cmd="twi" title="分享到推特"></a>
            <a href="#" class="fa fa-weibo bds_tsina" data-cmd="tsina" title="分享到新浪微博"></a>
            <a href="#" class="fa fa-qq bds_sqq" data-cmd="sqq" title="分享给 QQ 好友"></a>
            <a href="#" class="fa fa-files-o bds_copy" data-cmd="copy" title="复制网址"></a>
            <a href="#" class="fa fa fa-envelope-o bds_mail" data-cmd="mail" title="通过邮件分享"></a>
            <a href="#" class="fa fa-weixin bds_weixin" data-cmd="weixin" title="生成文章二维码"></a>
            <a href="#" class="fa fa-share-alt bds_more" data-cmd="more"></i></a>
        </div>
        <script>
            window._bd_share_config={
                "common":{"bdSnsKey":{},"bdText":"Android statusBar 开发问题汇总　| 高新兴移动开发小组　","bdMini":"2","bdMiniList":false,"bdPic":"","bdStyle":"0","bdSize":"24"},"share":{}};with(document)0[(getElementsByTagName('head')[0]||body).appendChild(createElement('script')).src='http://bdimg.share.baidu.com/static/api/js/share.js?v=89860593.js?cdnversion='+~(-new Date()/36e5)];
        </script>
    

    
</div>







    
      <div class="duoshuo" id="comments">
    <div id="comment-box" ></div>
    <div class="ds-thread" id="ds-thread" data-thread-key="2017/12/25/Android-statusBar-开发问题汇总/" data-title="Android statusBar 开发问题汇总" data-url="https://gosuncnstudio.github.io/2017/12/25/Android-statusBar-开发问题汇总/"></div>
    <script>
        var duoshuoQuery = {short_name:""};
        var loadComment = function(){
            var d = document, s = d.createElement('script');
            s.src = (document.location.protocol == 'https:' ? 'https:' : 'http:') + '//static.duoshuo.com/embed.js';
            s.async = true; s.charset = 'UTF-8';
            (d.head || d.body).appendChild(s);
        }

        
    </script>
    
    <script> loadComment(); </script>

</div>
    




    <div class="scroll" id="post-nav-button">
        
            <a href="/2017/12/27/Android编译时注解/" title="Pre: Android编译时注解">
                <i class="fa fa-angle-left"></i>
            </a>
        

        <a title="Mini Archives"><i class="fa fa-bars"></i><i class="fa fa-times"></i></a>

        
            <a href="/2017/12/18/Git常用命令简介/" title="Next: Git常用命令简介">
                <i class="fa fa-angle-right"></i>
            </a>
        
    </div>

    <ul class="post-list"><li class="post-list-item"><a class="post-list-link" href="/2018/01/16/svn与Cocoapods联用方法/">svn与Cocoapods联用方法</a></li><li class="post-list-item"><a class="post-list-link" href="/2018/01/04/适配iOS-11总结/">适配iOS 11总结</a></li><li class="post-list-item"><a class="post-list-link" href="/2018/01/04/Carthage-使用手册/">Carthage 使用手册</a></li><li class="post-list-item"><a class="post-list-link" href="/2017/12/27/Android编译时注解/">Android编译时注解</a></li><li class="post-list-item"><a class="post-list-link" href="/2017/12/25/Android-statusBar-开发问题汇总/">Android statusBar 开发问题汇总</a></li><li class="post-list-item"><a class="post-list-link" href="/2017/12/18/Git常用命令简介/">Git常用命令简介</a></li><li class="post-list-item"><a class="post-list-link" href="/2017/12/15/视频码流格式解析/">视频码流格式解析</a></li><li class="post-list-item"><a class="post-list-link" href="/2017/12/07/破解摩拜成为私家车的有效方法/">破解摩拜成为私家车的有效方法</a></li><li class="post-list-item"><a class="post-list-link" href="/2017/12/06/Android内存泄漏总结/">内存泄漏总结</a></li><li class="post-list-item"><a class="post-list-link" href="/2017/12/05/hexo使用教程/">hexo使用教程</a></li><li class="post-list-item"><a class="post-list-link" href="/2017/12/05/hexo样式/">hexo样式及md语法教程</a></li><li class="post-list-item"><a class="post-list-link" href="/2017/12/04/GXXVideoPlayer配置/">GXXVideoPlayer配置</a></li></ul>




    <script>
        
    </script>
</div>
      <footer id="footer">
    <div class="outer">
        <div id="footer-info">
            <div class="footer-left">
                <i class="fa fa-copyright"></i> 
                1997-2018 GosuncnStudio
            </div>
            <div class="footer-right">
                <a href="http://hexo.io/" target="_blank" title="A fast, simple &amp; powerful blog framework">Hexo</a>  Theme <a href="https://github.com/MOxFIVE/hexo-theme-yelee" target="_blank" title="Another simple and elegant theme for Hexo  v3.5">Yelee</a> by MOxFIVE <i class="fa fa-heart animated infinite pulse"></i>
            </div>
        </div>
        
            <div class="visit">
                
                    <span id="busuanzi_container_site_pv" style='display:none'>
                        <span id="site-visit" title="Site Visitors"><i class="fa fa-user" aria-hidden="true"></i><span id="busuanzi_value_site_uv"></span>
                        </span>
                    </span>
                
                
                    <span>| </span>
                
                
                    <span id="busuanzi_container_page_pv" style='display:none'>
                        <span id="page-visit"  title="Page Hits"><i class="fa fa-eye animated infinite pulse" aria-hidden="true"></i><span id="busuanzi_value_page_pv"></span>
                        </span>
                    </span>
                
            </div>
        
    </div>
</footer>
    </div>
    
    <script src="/js/GithubRepoWidget.js"></script>

<script data-main="/js/main.js" src="//cdn.bootcss.com/require.js/2.2.0/require.min.js"></script>

    <script>
        $(document).ready(function() {
            var iPad = window.navigator.userAgent.indexOf('iPad');
            if (iPad > -1 || $(".left-col").css("display") === "none") {
                var bgColorList = ["#9db3f4", "#414141", "#e5a859", "#f5dfc6", "#c084a0", "#847e72", "#cd8390", "#996731"];
                var bgColor = Math.ceil(Math.random() * (bgColorList.length - 1));
                $("body").css({"background-color": bgColorList[bgColor], "background-size": "cover"});
            }
            else {
                var backgroundnum = 5;
                var backgroundimg = "url(/background/bg-x.jpg)".replace(/x/gi, Math.ceil(Math.random() * backgroundnum));
                $("body").css({"background": backgroundimg, "background-attachment": "fixed", "background-size": "cover"});
            }
        })
    </script>





    <script type="text/x-mathjax-config">
MathJax.Hub.Config({
    tex2jax: {
        inlineMath: [ ['$','$'], ["\\(","\\)"]  ],
        processEscapes: true,
        skipTags: ['script', 'noscript', 'style', 'textarea', 'pre', 'code']
    }
});

MathJax.Hub.Queue(function() {
    var all = MathJax.Hub.getAllJax(), i;
    for(i=0; i < all.length; i += 1) {
        all[i].SourceElement().parentNode.className += ' has-jax';                 
    }       
});
</script>

<script src="//cdn.bootcss.com/mathjax/2.6.1/MathJax.js?config=TeX-AMS-MML_HTMLorMML">
</script>


<div class="scroll" id="scroll">
    <a href="#" title="Back to Top"><i class="fa fa-arrow-up"></i></a>
    <a href="#comments" onclick="load$hide();" title="Comments"><i class="fa fa-comments-o"></i></a>
    <a href="#footer" title="Go to Bottom"><i class="fa fa-arrow-down"></i></a>
</div>
<script>
    // Open in New Window
    
        $("a[target=_blank]").removeAttr("target");
    
</script>

<script async src="https://dn-lbstatics.qbox.me/busuanzi/2.3/busuanzi.pure.mini.js">
</script>
  </div>
</body>
</html>